﻿using System;
using LeonardoNews.Models;

namespace LeonardoNews.Server.Models.ArticleModels
{
    public class CommentModel
    {
        public int ID { get; set; }

        public virtual UserModel User { get; set; }

        public string Text { get; set; }

        public int? ParentCommentId { get; set; }

        public static CommentModel FromComment(Comment comment)
        {
            CommentModel commentModel = new CommentModel()
            {
                ID = comment.ID,
                Text = comment.Text,
                User = comment.User == null ? null : UserModel.FromUser(comment.User)
            };

            if (comment.ParentComment != null)
            {
                commentModel.ParentCommentId = comment.ParentComment.ID;
            }

            return commentModel;
        }
    }
}